/*
Sample Input
24
39
0

Sample Output
6
3

 */
package com.yuan.algorithms.acm201503;

import java.math.BigInteger;
import java.util.Scanner;

public class HD1013整数各个位相加求根 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String n = sc.next();
			BigInteger bg = new BigInteger(n);
			bg = bg.mod(new BigInteger("9"));
			String t = bg.toString();
			if (n.equals("0")) {
				break;
			}
			if (t.equals("0")) {
				System.out.println(9);
			}else{
				System.out.println(t);
			}
		}

	}

}
